<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8" />
<title>后台欢迎页</title>
<link th:href="@{/css/resets.css}" rel="stylesheet" />
<link th:href="@{/css/content.css}" rel="stylesheet" />
<link th:href="@{/css/jeDate-test.css}" rel="stylesheet" />
<link th:href="@{/css/jedate.css}" rel="stylesheet" />
<style type="text/css">
.order-form {
	height: 80px;
	margin-left: 20px;
}

.control-group {
	float: left;
	width: 33%;
	margin-top: 10px;
}

label {
	width: 96px;
	text-align: right;
	display: table-cell;
	vertical-align: middle;
}

.control {
	display: table-cell;
	padding-left: 3px;
}

.control-input {
	width: 125px;
	height: 19px;
}

.control-button {
	float: right;
	padding-right: 320px;
	padding-top: 10px;
}

.control-button-input1 {
	background-color: #5fbbe4;
	border-color: #28a3ef;
	color: #fff;
	width: 65px;
	height: 30px;
	border: 0px;
}
.control-button-input2 {
	background-color: #72aa3f;
	border-color: #28a3ef;
	color: #fff;
	width: 65px;
	height: 30px;
	border: 0px;
}
.public-content .public-content-cont .public-cont-table{
	width:95%; 
	margin-left: 40px;
}
</style>
</head>
<body marginwidth="0" marginheight="0">
	<div class="container">
		<div class="public-content">
			<div class="public-content-header">
				<h3 style="color: #111111b3;">当前位置 :订单管理>订单列表</h3>
			</div>
			<form class="order-form" id="filterForm">
				<input type="hidden" id="pageNumber" name="pageNumber" value="1" />
				<input type="hidden" id="pageSize" name="pageSize" value="10" /> 
				<input type="hidden" id="page" name="page" /> 
				<input type="hidden" id="pageTotal" name="pageTotal" />
				<input type="hidden" id="username" name="username" />
				<div class="control-group">
					<label>订单编号:</label>
					<div class="control">
						<input type="text" class="control-input" id="orderId" name="orderId" />
					</div>
				</div>
				<div class="control-group">
					<label>收货人:</label>
					<div class="control">
					    <input type="text" class="control-input" id="consigneeInfo" name="consigneeInfo" />
					</div>
				</div>
				<!-- <div class="control-group">
					<label>供应商:</label>
					<div class="control">
					    <select id="orderState" style="width: 129px; height: 26px;">
					    </select>
					</div>
				</div> -->
				<div class="control-group">
					<label>订单状态:</label>
					<div class="control">
					    <select id="orderState" style="width: 129px; height: 26px;">
					       <option value="">请选择</option>
					       <option value="等待出库">等待出库 </option>
					       <option value="等待发货">等待发货</option>
					       <option value="等待确认收货">等待确认收货 </option>
					       <option value="暂停 ">暂停  </option>
					       <option value="完成 ">完成 </option>
					       <option value="取消">取消</option>
					       <option value="已锁定">已锁定</option>
					       <option value="等待发码">等待发码 </option>
					    </select>
					</div>
				</div>
				<div class="control-group">
					<label>下单时间:</label>
					<div class="control">
						<input type="text" class="control-input" id="startTime" name="startTime"  onclick="jeDate('#startTime',{trigger:false,format: 'YYYY-MM-DD'})"/>到
						<input type="text" class="control-input" id="endTime" name="endTime"  onclick="jeDate('#endTime',{trigger:false,format: 'YYYY-MM-DD'})"/>
					</div>
				</div> 
				<div class="control-button">
					<input type="button" value="查询" id="btn_query"
						class="control-button-input1"  onclick="userList();"/> <input type="button" value="重置"
						id="btn_reunion" class="control-button-input2" onclick="resets();" />
				</div> 
			</form>
			<div class="public-content-cont">
				<table class="public-cont-table">
					<thead>
						<tr>
							<th style="width: 15%"><table border="0" id="mytable"><tr style="border:0"><td width="320px" style="border-right:0">商品</td><td width="70px" style="border-right:0">单价(元)</td><td width="50px" style="border-right:0">数量</td></tr></table></th>
						<!-- 	<th style="width: 6%">单价(元)</th>
							<th style="width: 6%">数量</th> -->
							<th style="width: 10%">收货人</th>
							<th style="width: 10%">销售商家</th>
							<th style="width: 10%">订单状态</th>
							<th style="width: 10%">商品总额(元)</th>
							<th style="width: 6%">支付金额(元)</th>
							<th style="width: 15%">下单时间</th>
							<th style="width: 15%">操作</th>
						<!-- 	<th style="width: 20%">操作</th> -->
						</tr>
					</thead>
					<tbody id="userBoby">
					</tbody>
				</table>
				<div class="page" id="userPage">
					<form>
						 <a onclick="first();">首页</a> <a onclick="upper();">上一页</a> <a
							onclick="lower();">下一页</a>   第<span style="color: red; font-weight: 600" id="nxit">0</span>页
						共<span style="color: red; font-weight: 600" id="common">0</span>页  共<span style="color: red; font-weight: 600" id="lplplp">0</span>条数据<input
							type="text" class="page-input" id="jump" name="jump" /> <input type="button"
							class="page-btn" value="跳转" onclick="pageButton();" />
					</form>
				</div>
			</div>
		</div>
	</div>
</body>
<script th:src="@{/js/jquery-1.8.0.js}"></script>
<script th:src="@{/js/scripts.js}"></script>
<script th:src="@{/js/jedate.js}"></script>
<script th:src="@{/js/layer/layer.js}"></script>
<script th:inline="javascript">
  $("body").keydown(function() {
    if (event.keyCode == "13") {//keyCode=13是回车键
        $('#btn_query').click();
    }
  });

    $(function(){
    	userList();
    	$("#jump").val("");
    });
    
    //订单列表
    function userList(){
      	var url = [[${#httpServletRequest.getContextPath()}]]+'/order/querypage';
	    $.ajax({
				cache : false,
				type : "POST",
				url : url,
				async : false,
				dataType : "json",
				data : {
					page : $("#pageNumber").val(),
					pageSize : $("#pageSize").val(),
					state : $("#state option:selected").val(),
					orderStateRemark : $("#orderState option:selected").val(),
					orderId : $("#orderId").val(),
					consigneeInfo : $("#consigneeInfo").val(),
					startTime : $("#startTime").val(),
					endTime : $("#endTime").val()
				},
				success : function(data) {
					var order = data.rows;
					if(order != null){
						var str = "";
						/* <![CDATA[ */
						for (var i = 0; i < order.length; i++) {
							str += "<tr><td class='center'>";
							  str +="<div style='margin: 0 auto'>";
							  str +="<span style='display:inline-block; float: left; padding-left: 20px;margin: 10px 0;'>订单编号："+ order[i].cell.orderId +"</span><br>";
							var proudct = JSON.parse(order[i].cell.productInfo);
							for(var j = 0; j < proudct.length; j++){
								  str +="<table style='width: 430px;margin-bottom:10px;' border='0' cellpadding='0' cellspacing='0'>";
								  str +="<tbody><tr style='border:0'><td align='center' width='90px' style='border : none'><img src='"+ proudct[j].images +"' style='width:80px; height:80px'></td>";
								  str +="<td align='center' width='250px' style='border : none'><span style='color: red'>商品货号："+ proudct[j].productNo +"</span><br>"+  proudct[j].title +"</td>";
								  str +="<td style='text-align:center; padding: 0px 0px 13px; border : none' width='80px'>"+ proudct[j].jdPrice +"</td><td style='text-align:center; padding: 0px 0px 13px; border : none' width='50px'>"+ proudct[j].itemTotal +"</td>";
								  str +="</tr></tbody></table>";
							}
							str += "</div>";
							str +="</td>";
							str += "<td >" + JSON.parse(order[i].cell.consigneeInfo).fullname +"</td>";
							str += "<td >" + order[i].cell.merchantId +"</td>";
				/* 			if(order[i].cell.orderState == 'WAIT_SELLER_STOCK_OUT'){
								str += "<td >等待出库</td>";
							}else if(order[i].cell.orderState == 'WAIT_GOODS_RECEIVE_CONFIRM'){
								str += "<td >等待确认收货 </td>";
							}else if(order[i].cell.orderState == 'WAIT_SELLER_DELIVERY'){
								str += "<td >等待发货</td>";
							}else if(order[i].cell.orderState == 'POP_ORDER_PAUSE'){
								str += "<td >暂停  </td>";
							}else if(order[i].cell.orderState == 'FINISHED_L' || order[i].cell.orderState == 'WanCheng'){
								str += "<td >完成</td>";
							}else if(order[i].cell.orderState == 'TRADE_CANCELED'){
								str += "<td >取消</td>";
							}else if(order[i].cell.orderState == 'LOCKED'){
								str += "<td >已锁定</td>";
							}else if(order[i].cell.orderState == 'WAIT_SEND_CODE'){
								str += "<td >等待发码 </td>";
							}else{
								str += "<td ></td>";
							} */
							str += "<td >" + order[i].cell.orderStateRemark +"</td>";
							str += "<td >" + order[i].cell.orderTotalPrice +"</td>";
							str += "<td >" + order[i].cell.orderPayment +"</td>";
							str += "<td >" + getMyDate(order[i].cell.orderStartTime) +"</td>";
							if(order[i].cell.orderStateRemark == '等待出库' || order[i].cell.orderStateRemark == '等待发货'){
								str +="<td ><button style='background-color: #5fbbe4;color: aliceblue; width: 80px; height: 28px; border: 0;' onclick='dispay(\""+order[i].cell.orderId+"\");'>查看详情</button>&nbsp;&nbsp;&nbsp;&nbsp;<button style='background-color: #ff831e;color: aliceblue; width: 80px; height: 28px; border: 0;' onclick='detail(\""+order[i].cell.orderId+"\");'>发货</button></td></tr>";
							}else{
								str +="<td ><button style='background-color: #5fbbe4;color: aliceblue; width: 80px; height: 28px; border: 0;' onclick='dispay(\""+order[i].cell.orderId+"\");'>查看详情</button></td></tr>";
							}
						}
						/* ]]> */
						$("#userBoby").html(str);
						$("#page").val(data.page);
						$("#nxit").text(data.page);
						$("#lplplp").text(data.total);
						/* <![CDATA[ */
						var t = 1;
						for (var j = 1; j < data.total / 10; j++) {
							t++;
						}
						/* ]]> */
						$("#common").text(t);
						$("#pageTotal").val(t);
					}else{
						$("#page").val(0);
						$("#nxit").text(0);
						$("#common").text(0);
						$("#userBoby").html("");
						$("#pageTotal").val(0);
					} 
				}
       }); 
    }
    
    //首页
    function first(){
        $("#pageNumber").val(1);
        $("#jump").val("");
		userList();
    };
    
    //上一页
    function upper(){
    	var pa = $("#page").val();
    	 if(pa > 1){
     		$("#pageNumber").val(parseInt(pa)-1);
     	 } 
    	 $("#jump").val("");
		userList();
    };
    
    //下一页
    function lower(){
    	var toatl = [];
		var to = parseInt($("#pageTotal").val());
		var pa = parseInt($("#page").val());
	    if(to > pa){
    		$("#pageNumber").val(parseInt(pa)+1);
    	} 
	    $("#jump").val("");
		userList();
    };
    
    //跳转
    function pageButton(){
    	var jump = $("#jump").val();
    	var to = parseInt($("#pageTotal").val());
		var pa = parseInt($("#page").val());
	    if(jump >= pa){
	    	if(to >= jump){
	    		$("#pageNumber").val(jump);
	        } 
	    } 
		userList();
    };
    
    //重置
    function resets(){
    	document.getElementById('filterForm').reset();
    	userList();
    }
    
    //时间戳转换
    function getMyDate(str){  
        var oDate = new Date(str),  
        oYear = oDate.getFullYear(),  
        oMonth = oDate.getMonth()+1,  
        oDay = oDate.getDate(),  
        oHour = oDate.getHours(),  
        oMin = oDate.getMinutes(),  
        oSen = oDate.getSeconds(),  
        oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间  
        return oTime;  
    }; 
    
    //填充0
    function getzf(num){
    	/* <![CDATA[ */
        if(parseInt(num) < 10){  
            num = '0'+num;  
        }  
        /* ]]> */
        return num;  
   }
    
    //发货
    function detail(orderId){
    	var layerIndex = layer.open({
			type : 2,
			shade : [0.3,'#000'],
			fix : false,
			title : '查看商品',
			maxmin : true,
			Method : "POST",
			content : [[${#httpServletRequest.getContextPath()}]]+'/order/delivery?orderId='+orderId,
			area : [ '450px', '250px' ],
			end : function(index) {
				userList();
			}
		});
    }
    
   //查看详情
   function dispay(orderId){
	   window.location.href =[[${#httpServletRequest.getContextPath()}]]+"/order/detail?orderId="+orderId;
   }

</script>
</html>
